package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.activity.chips.ChipsCollectActivityService;
import com.xcity.game.activity.chips.ChipsCollectReward;
import com.xcity.game.common.PlayerPool;
import com.xcity.game.item.ItemTemplate;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class ActivityChipsCollectInfoResponse extends Response {
	
	public int id;
	public int state; // 拼图状态
	public ChipsCollectReward reward;
	public List<Chip> chips;
	public int count; // 已领奖次数
	public int maxCount; // 最多可领奖次数
	
	public static class Chip {
		public int id;
		public String name;
		public String icon;
		public int count;
		public byte used; // 0-未使用, 1-已使用
		public Chip(ItemTemplate item, int count, byte used) {
			this.id = item.getId();
			this.name = item.getName();
			this.icon = item.getIcon();
			this.count = count;
			this.used = used;
		}
	}
	
	public ActivityChipsCollectInfoResponse(int serial, Player player, ChipsCollectReward reward, ItemTemplate[] chipItems) {
		super(serial);
		this.state = player.getPool().getIntValue(PlayerPool.PROPERTY_CHIPS_COLLECT_STATE);
		this.count = player.getPool().getIntValue(PlayerPool.PROPERTY_CHIPS_COLLECT_REWARD_TIMES);
		this.maxCount = ChipsCollectActivityService.MAX_REWARD_TIMES;
		this.reward = reward;
		int len = chipItems.length;
		this.chips = new ArrayList<>(len);
		for (int i = 0; i < len; i++) {
			ItemTemplate item = chipItems[i];
			int count = player.getBag().countOf(item.getId());
			byte used = (byte) (state >> i & 1);
			Chip chip = new Chip(item, count, used);
			this.chips.add(chip);
		}
	}

}
